package com.dg.acb.utils;

import android.database.Cursor;

public class CursorUtil {

    public static long getLong(Cursor c, String key) {
        int index = c.getColumnIndex(key);
        if (index < 0) {
            throw new IllegalStateException("column not exist or not selected:" + key);
        }
        return c.getLong(index);
    }

    public static int getInt(Cursor c, String key) {
        int index = c.getColumnIndex(key);
        if (index < 0) {
            throw new IllegalStateException("column not exist or not selected:" + key);
        }
        return c.getInt(index);
    }

    public static short getShort(Cursor c, String key) {
        int index = c.getColumnIndex(key);
        if (index < 0) {
            throw new IllegalStateException("column not exist or not selected:" + key);
        }
        return c.getShort(index);
    }

    public static byte[] getBlob(Cursor c, String key) {
        int index = c.getColumnIndex(key);
        if (index < 0) {
            throw new IllegalStateException("column not exist or not selected:" + key);
        }
        return c.getBlob(index);
    }

    public static String getString(Cursor c, String key) {
        int index = c.getColumnIndex(key);
        if (index < 0) {
            throw new IllegalStateException("column not exist or not selected:" + key);
        }
        return c.getString(index);
    }

    public static float getFloat(Cursor c, String key) {
        int index = c.getColumnIndex(key);
        if (index < 0) {
            throw new IllegalStateException("column not exist or not selected:" + key);
        }
        return c.getFloat(index);
    }
}
